global infile "DataMain.dta"
global outfile "$results\Figure 2"

	
* Create means

use "$infile", clear
drop if dupindicator == 1

sum week if week2 == 34  
replace week = 80 if week >= 77
replace week2 = 37 if week2 >= 34
egen watercohort = mean(water), by(cohort week)
egen logwatercohort = mean(logwater), by(cohort week)
duplicates drop cohort week, force
sort cohort week


* Figure 2. Windowed plots

twoway (line logwatercohort week if cohort == 1 & weeksDD == 1) ///
(line logwatercohort week if cohort == 2 & weeksDD == 1, lp(dash)), ///
xli(-0.5, lc(navy)) graphregion(color(white)) ///
ti("A. Log use for Group 1 vs. Controls") yti("Log (use+1)") xti("Event week in Period 1") ///
xsc(r(-30 40)) xlab(-30(10)30) ///
leg(lab(1 "Treated group") lab(2 "Control group") region(lc(white))) 
graph save "$results\TempA", replace

twoway (line logwatercohort week2 if cohort == 2 & weeksDD == 2) ///
(line logwatercohort week2 if cohort == 1 & weeksDD == 2, lp(dash)) ///
(scatter logwatercohort week2 if cohort == 2 & week2 >= 34, mc(navy)) ///
(scatter logwatercohort week2 if cohort == 1 & week2 >= 34, mc(maroon)), ///
xli(-0.5, lc(navy)) graphregion(color(white)) leg(off) ///
ti("B. Log use for Group 2 vs. Controls") yti("Log (use+1)") xti("Event week in Period 2") ///
xsc(r(-30 40)) xlab(-30(10)30 37 "34-191")
graph save "$results\TempB", replace

twoway (line logwatercohort week2 if cohort == 3 & weeksDD == 2) ///
(line logwatercohort week2 if cohort == 1 & weeksDD == 2, lp(dash)) ///
(scatter logwatercohort week2 if cohort == 3 & week2 >= 34, mc(navy)) ///
(scatter logwatercohort week2 if cohort == 1 & week2 >= 34, mc(maroon)), ///
xli(-0.5, lc(navy)) graphregion(color(white)) leg(off) ///
ti("C. Log use for Group 3 vs. Controls") yti("Log (use+1)") xti("Event week in Period 2") ///
xsc(r(-30 40)) xlab(-30(10)30 37 "34-191")
graph save "$results\TempC", replace

grc1leg "$results\TempA" "$results\TempB" "$results\TempC", ///
rows(3) graphregion(color(white)) iscale(0.7) ycommon name(grc, replace) 
gr draw grc, ysize(8.5) 
graph save "$outfile", replace

